<?php
/**
 * 内容管理视图
 *
 *
 *
 */
// 排序
$arr_orderby    = array(
    'id'        => '&orderby=id',
    'startime'  => '&orderby=startime',
    'addtime'=> '&orderby=addtime',
    'endtime'  => '&orderby=endtime',
    'display'  => '&orderby=display',
    );
$orderby    = strtolower(trim(@$_GET['orderby']));
if(array_key_exists($orderby, $arr_orderby)) {
    $order_asc  = @(int)$_GET['desc'];
    $arr_orderby[$orderby] .= $order_asc == 0 ? '&desc=1' : '&desc=0';
} else {
    $arr_orderby['id'] .= '&desc=0';
}

// 保存数据框架名
$save_frame = $_SESSION[$G_admin_session_key]['save_frame'];
$back_url   = get_current_url();
// 将当前URL保存在Cookie中，避免复杂的URL字符串
cookie('back_url', strcode($back_url));
$url_cur    = get_current_url(array('orderby', 'desc'));


/**
 * 搜索参数处理
 *
 */
// 关键字
$key            = trim(@$_GET['key']);
// 是否包含子类
$class_id       = @(int)$_GET['class_id'];
$class_all      = @(int)$_GET['class_all'];
$chk_class_all  = ($class_all==1) ? ' checked' : '';
// 是否有效
$display       = trim(@$_GET['display']);
$chk_display_all   = '';
$chk_display__1    = '';
$chk_display_1     = '';
if($display == -1) {
    $chk_display__1 = ' checked';
} elseif($display == 1) {
    $chk_display_1 = ' checked';
} else {
    $chk_display_all = ' checked';
}


$begin_date = @$_GET['begin_date'];
$end_date   = @$_GET['end_date'];
$is_ad      = @(int)$_GET['is_ad'];

$dsp_ad     = ($is_ad == 1) ? 'style="display:block"':'style="display:none"';



$chk_haveimg    = @(int)$_GET['haveimg'] == 1 ? ' checked':'';
$chk_top        = @(int)$_GET['top'] == 1 ? ' checked':'';
$chk_new        = @(int)$_GET['new'] == 1 ? ' checked':'';
$chk_recommend  = @(int)$_GET['recommend'] == 1 ? ' checked':'';

// + -------------------------------------- + //
// 排序处理 - 为排序加上小图标

$order_by   = @trim($_GET['orderby']);
$order_desc = @(int)$_GET['desc'];

if($order_by != '') {
    $order_desc = ($order_desc!=1) ? 'sort_asc' : 'sort_desc' ;
    $this_param_style  = $order_by . '_style';
    $$this_param_style = '<div class="' . $order_desc . '"></div>';
}

// + -------------------------------------- + //


require($abs_admin_cppath . '/header.php');
?>
<SCRIPT LANGUAGE="JavaScript" SRC="<?php echo $url_global['common']; ?>/js/popcalendar.js"></SCRIPT>


<div class="spH10"></div>


<div class="datacontainer1" id="listDiv">
<form action="<?php echo $mod_url['li'] ?>" name="search" method="get">
<div class="new_line">
<input type="hidden" name="mod" value="<?php echo $mod ?>">
<input type="hidden" name="action" value="<?php echo $action ?>">
<input type="hidden" name="cata" value="<?php echo $cata ?>">



	<div class="spW10 fl"></div>
	<a href="<?php echo $mod_url['add'] ?>"  class="btn fl">新增广告</a>


<INPUT TYPE="radio" NAME="display" id="display_all" value="0" <?php echo $chk_display_all?>> <label for="display_all">所有</label>
<INPUT TYPE="radio" NAME="display" id="display__1" value="-1" <?php echo $chk_display__1?>> <label for="display__1">不显示</label>
<INPUT TYPE="radio" NAME="display" id="display_1" value="1" <?php echo $chk_display_1?>> <label for="display_1">显示</label>
&nbsp;&nbsp;
<SCRIPT LANGUAGE="JavaScript">
<!--
var adpos   = <?php echo js_pagepos($ad_position) ?>;



function pagepos_change(o, id) {
    var key = o.options[o.selectedIndex].value;
    var opt = GE(id);
    option_remove(id);
    if(key == '') return false;

    var arr = adpos[key];
    for(var i=0; i < arr.length; i++) {
        var items   = new Option(arr[i][1],arr[i][1]);
        items.width = arr[i][2];
        items.height= arr[i][3];
        opt.options.add(items);
        
    }
}
function pos_change(o) {
    var item = o.options[o.selectedIndex];
    var form = o.form;

    form.elements['ad[width]'].value    = item.width;
    form.elements['ad[height]'].value   = item.height;
}
function pos_inti(pos) {
    var o = GE('pagepos');
    pagepos_change(o, 'pos');


    var opt = GE('pos');
    for(var i=0; i < opt.length; i++) {
        if(pos == opt.options[i].value) {
            opt.selectedIndex = i;
            break;
        }
    }
}
function option_remove(id) {
    var o   = GE(id);
    for(var i=o.length-1; i>0; i--) {
        o.options.remove(i);
    }
}
//-->
</SCRIPT>
		<select name="pagepos" id="pagepos" onchange="pagepos_change(this, 'pos')" class="select01">
		<?php echo pagepos_option($ad_position, $pagepos) ?>
		</select>


		<select name="pos" id="pos" onchange="pos_change(this)" class="select01">
		<option value="">不属于任何位置</option>
		</select>
<SCRIPT LANGUAGE="JavaScript">
<!--
pos_inti('<?php echo $pos?>');
//-->
</SCRIPT>
&nbsp;&nbsp;
<input type="text" name="key" value="<?php echo $key?>" size="10" class="text">


	<input type="submit" value="查询" class="btn">
	&nbsp;&nbsp;
</div>
</form>
<form action="<?php echo $mod_url['del'] ?>" name="items_form" method="post" target="<?php echo $save_frame?>" onsubmit="return submit_select_items(this.name, 'item_id[]');">
<TABLE BORDER="0" CELLPADDING="4" CELLSPACING="1" width="100%" class="list_table">
<THEAD>
	<TR class="list_head">
		<TH scope=col width="30"><a href="<?php echo $url_cur ?><?php echo $arr_orderby['id'] ?>"><?php echo $id_style;?>#</a></TH>

		<TH scope=col width="100">所属页面</TH>
		<TH scope=col width="160">所在位置</TH>
		<TH scope=col width="160">购买期限</TH>
		<TH scope=col width="96"><a href="<?php echo $url_cur ?><?php echo $arr_orderby['addtime'] ?>"><?php echo $addtime_style;?>发布时间</a></TH>
		<TH width="160" scope=col><a href="<?php echo $url_cur ?><?php echo $arr_orderby['startime'] ?>"><?php echo $startime_style;?>生效时间</a></TH>
		<TH width="160" scope=col><a href="<?php echo $url_cur ?><?php echo $arr_orderby['endtime'] ?>"><?php echo $endtime_style;?>结束时间</a></TH>
        <TH scope=col width="100">状态</TH>
		<TH scope=col width="89"><a href="<?php echo $url_cur ?><?php echo $arr_orderby['display'] ?>"><?php echo $display_style;?>是否生效</a></TH>
        </TR>
		</THEAD>
<TBODY>
<?php
$tr_class = '';
if(!empty($record) && sizeof($record) > 0) {
    foreach($record as $k=>$v) {
        $tr_class   = $tr_class != 'tr0' ? 'tr0' : 'tr1';
        $id     = $v['id'];
        $pagepos  = $v['pagepos'];
        $pos  = $v['pos'];
        $gmsj  = $v['gmsj'];


   if($v["display"]==0){
			$display="<font color='#f00'>审核中</font>";
			$endtime="--";
			$startime="--";
	}elseif($v["display"]==1){
		$display="<font color='#060'>展示中</font>";				
		$endtime=date("Y-m-d H:i:s",$v["endtime"]);
		$startime=date("Y-m-d H:i:s",$v["startime"]);
	}else{
		$display="<font color='#ccc'>已过期</font>";
		$endtime="--";
		$startime="--";
	}

        $txt_display = $v['display'] == 1 ? "<div class=\"btn_yes\" onclick=\"listTable.toggle(this, 'display', 1, '$id','toggle1')\">{$v['display']}</div>" : "<div class=\"btn_no\" onclick=\"listTable.toggle(this, 'display', 1, '$id','toggle1')\">0</div>";
        $txt_create_time = date(DATE_FORMAT, $v['addtime']);

        // 截取
        $title_cut  = (zh_strlen($title)>=48)? zh_substr($title, 48) : $title;
?>
	<TR class="<?php echo $tr_class; ?>" onmouseover="return chgBg(this, 1);" onmouseout="return chgBg(this, 0);">
		<TD width="30" class="textC"><input type="checkbox" value="<?php echo $id ?>" name="item_id[]"></TD>
		<TD class="textC"><?php echo $pagepos ?></TD>
		<TD class="textC"><?php echo $pos ?></TD>
		<TD class="textC"><?php echo $gmsj ?>个月</TD>
		<TD width="96" class="time01 textC"><?php echo $txt_create_time ?></TD>
		<TD class="textC"><?php echo $startime ?></TD>
		<TD class="textC"><?php echo $endtime ?></TD>
        <TD width="100" class="textC"><?php echo $display ?></TD>
		<TD width="89" class="textC"><?php echo $txt_display ?></TD>
		</TR>
<?php
    }
} else {
?>
<TR class="tr0" onmouseover="return chgBg(this, 1);" onmouseout="return chgBg(this, 0);">
<TD colspan="7">没有或没有找到合适的记录！</td>
</td>
<?php
}
?>
</TBODY>
</TABLE>
<?php
// 分页
$page_info  = "$record_total 条记录 共 $page_total 页 ";
$page_list  = get_page_nav($page_total);
?>
<div class="page_nav">
	<div class="page_info">
		<?php echo $page_info ?>
	</div>
	<div class="page_list_pre">
		&nbsp;&nbsp;<a href="javascript:void(0);" onclick="chkbox_sel_all('items_form', 'item_id[]');"><B>全选</B></a> <a href="javascript:void(0);" onclick="chkbox_sel_reverse('items_form', 'item_id[]');"><B>反选</B></a>
	</div>
	<div class="page_list">
		<?php echo $page_list?>
	</div>
</div>
<div class="new_line">
<input type="submit" name="del" value="删除" class="btn fl">
<input type="hidden" name="deltype" value="all">

</div>
</form>
		</div>
</div>

<?php
require($abs_admin_cppath . '/footer.php');
?>